<#assign base = request.contextPath />
<!DOCTYPE html>
<html lang="zh-CN">
<head>

    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>系统登录</title>
    <base id="base" href="${base}">
    <!-- Bootstrap -->
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">

    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootbox.js/4.4.0/bootbox.min.js"></script>
    <script src="${base}/res/js/common.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="${base}/res/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="${base}/res/css/body.css"/>
</head>
<body>
<div class="container">
    <section id="content">
        <form action="" id="loginForm">
            <h1>系统登录</h1>
            <div>
                <input type="text" placeholder="用户名" id="username"/>
            </div>
            <div>
                <input type="password" placeholder="密码" id="password"/>
            </div>
            <div>
                <a href="${base}/admin/reg">企业注册</a>
                <input type="submit" value="登录" id="js-btn-login"/>
            </div>
        </form><!-- form -->
        <div class="button">
            &copy; 东方物流
        </div> <!-- button -->
    </section><!-- content -->
</div>
<!-- container -->
</body>
</html>

<script type="text/javascript">
    $(document).ready(function () {
        $('#loginForm').submit(function () {
            var username = $('#username').val();
            var password = $('#password').val();

            $.ajax({
                type: 'post',
                url: API_UCENTER_USER_LOGIN,
                dataType: "json",
                data: {
                    username: username,
                    password: password
                },
                success: function (data) {
                    saveToken(data.token);
                    saveUserAccount(JSON.stringify(data));
                    location.href = $('#base').val() + '/admin/home';
                },
                error: function (jqXHR) {
                    bootbox.alert(jqXHR.responseJSON.message);
                }
            });
            return false;
        });

        $('#js-btn-login').click(function () {

        });
    })
</script>
